package com.hospital.yygh.msm.receiver;

import com.hospital.yygh.common.constant.MqConst;
import com.hospital.yygh.msm.service.MsmService;
import com.hospital.yygh.vo.msm.MsmVo;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * 封装msm发送消息的mq监听器：
 *
 */
@Component
public class MsmReceiver {
    // 下单-》预约下单mq监听接收，hosp模块更新排班信息,order号源更新-》通过mq发送消息-》msm监听器接收，发送短信操作
    // 监听hosp，order->发送的消息到mq，msm模块(MsmReceiver)监听并接收到消息，调用sendEmail方法发送QQ邮箱短信
    // 消息存储在msmVo，通过msmService.sendEmail(**)发送

    @Autowired
    private MsmService msmService;

    /**
     * @RabbitListener 里面是rabbit-util配置的常量类
     * @param msmVo
     * @param message
     * @param channel
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = MqConst.QUEUE_MSM_ITEM, durable = "true"),
            exchange = @Exchange(value = MqConst.EXCHANGE_DIRECT_MSM),
            key = {MqConst.ROUTING_MSM_ITEM}
    ))
    public void sendEmail(MsmVo msmVo, Message message, Channel channel) {
        msmService.sendEmail(msmVo);
    }


}
